package com.bootcamp.java;

/**
 * @program: code
 * @description: traverse all odd numbet within 100
 * @author: Keyu li
 * @create: 2021-08-24 20:14
 **/

public class OddNumberWithinOneHundred {
    public static void main(String[] args) {
        printAllOdd(100);
        System.out.println(sumAllOdd(100));

    }

    private static int sumAllOdd(int n) {
        int sum = 0;
        for (int i = 1 ; i <= n; i+=2) {
            sum += i;
        }
        return sum;
    }

    private static void printAllOdd(int n) {
        for (int i = 1 ; i <= n; i+=2) {
            System.out.print(i+" ");;
        }
        System.out.println();
    }
}
